package doubleZhiZhen;

public class XunZhaoMinXuLie {

    //TODO:2023/9/19 寻找最小子序列

    public static int find(int[] nums, int target) {

        int left = 0;
        int n = nums.length;
        int sum = 0;
        int minLength = n + 1;
        for (int right = 0; right < n; right++) {
            sum += nums[right];

            while (sum >= target) {
                int currentLength = right - left + 1;
                minLength = Math.min(minLength, currentLength);
                sum -= nums[left];
                left++;
            }

        }

        return minLength > n ? 0 : minLength;

    }

}
